package com.payment.paymentmanagersystem.controller;

import com.payment.paymentmanagersystem.dal.PaymentDAL;
import com.payment.paymentmanagersystem.dal.UserDAL;
import com.payment.paymentmanagersystem.model.PayOrderInfo;
import com.payment.paymentmanagersystem.model.UserInfo;
import com.payment.paymentmanagersystem.unit.Response;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 支付功能API
 * @author 李耀华
 * @date 2023年6月14日
 */

@RestController
public class PaymentController {
    @Autowired
    PaymentDAL paymentDAL;

    @Autowired
    UserDAL userDAL;


    /**
     * 生成收款二维码
     * @param order
     * @return
     */
    @CrossOrigin
    @ResponseBody
    @RequestMapping(value = "/getPayeeInfo", method = RequestMethod.POST, produces = "application/json; utf-8")
    public Response getPayeeInfo(@RequestBody PayOrderInfo order) {
        System.out.println("被请求到！"+order.getTimes());
        return null;
    }

    /**
     * 验证收款码是否合法
     */
    @CrossOrigin
    @RequestMapping(value = "/fkx", method = RequestMethod.POST, produces = "application/json; utf-8")
    public Response validateFKurl(@RequestBody UserInfo user){
        System.out.println("请求到验证收款信息");
        UserInfo payee = userDAL.validatePayeeUser(user);
        if(payee!=null){
            return new Response(200,"验证成功",payee);
        }else {
            return new Response(203,"验证失败",null);
        }
    }

    /**
     * 付款人扫码付款
     */
    @CrossOrigin
    @RequestMapping(value = "/fkpay", method = RequestMethod.POST, produces = "application/json; utf-8")
    public Response paymentPayByQrcode(@RequestBody PayOrderInfo order){
        System.out.println("请求付款功能");
        if(paymentDAL.createPayOrder(order)){
            //执行成功
            return new Response(200,"支付成功！",order.getOrder_payMoney());
        }else{
            return new Response(203,"支付失败！",null);
        }
    }
}
